<?php
namespace app\index\controller;
use app\index\controller\Base;
use app\index\model\Set;
use app\index\model\Game;
use app\index\model\Pool;
use app\index\model\Box;
use think\Db;
use think\Request;

class Qn extends Base
{
    /**
     * 写入页面装饰信息
     *
     * @return void
     * @author 
     **/
    public function set()
    {
        $data=$this->reqeust->param();
        $check=$this->check('set');
        if($check){
            $set=new Set;
            $set->allowField(true)->save($data,['mini_app_id'=>$mini_app_id]);
            $this->success;
        }else{
            $set=new Set($data);
            $set->allowField(true)->save();
            $this->success(); 
        }
    }
    /**
     * 写入玩法逻辑信息
     *
     * @return void
     * @author 
     **/
    public function game()
    {
        $data=$this->reqeust->param();
        $check=$this->check('game');
        if($check){
            $game=new Game;
            $game->allowField(true)->save($data,['mini_app_id'=>$mini_app_id]);
            $this->success;
        }else{
            $game=new Game($data);
            $game->allowField(true)->save();
            $this->success(); 
        }
    }
    /**
     * 写入奖池信息
     *
     * @return void
     * @author 
     **/
    public function pool()
    {
        $data=$this->reqeust->param();
        $check=$this->check('pool');
        if($check){
            $pool=new Pool;
            $pool->allowField(true)->save($data,['mini_app_id'=>$mini_app_id]);
            $this->success;
        }else{
            $pool=new Pool($data);
            $pool->allowField(true)->save();
            $this->success(); 
        }

    }
    /**
     * 获取中奖信息
     *
     * @return void
     * @author 
     **/
    public function box()
    {
        $mini_app_id=$this->request->param('mini_app_id');
        $data=Box::get(['mini_app_id'=>$mini_app_id,'status'=>1]);
        $this->success($data);
        

    }
    /**
     * 检查数据库中是否含有mini_app_id
     *
     * @return void
     * @author 
     **/
    public function check($db)
    {
        //$data=Request::instance()->param();
        $mini_app_id=Request::instance()->param('mini_app_id');
        $data=Db::name($db)->where(['mini_app_id'=>$mini_app_id])->find();
        if(count($data)==0){
            return false;
        }else{return true;}

    }
   


}
